<template>
  <div class="statistics-tabs">
    <el-tabs v-model="activeName" type="border-card">
      <el-tab-pane label="统计视图" name="chart">
        <chart />
      </el-tab-pane>
      <!--            <el-tab-pane label="数据分析" name="analysis">
                                                    <analysis/>
                                                </el-tab-pane>-->
      <el-tab-pane label="测评报告" name="report" v-if="type == 5 || type == 6">
        <Report ref="report" v-if="type == 5"></Report>
        <Report360 ref="report360"> v-else </Report360>
        <!--                <router-view/>-->
      </el-tab-pane>

      <el-tab-pane label="得分区间" name="score" v-if="type == 6">
        <score-level ref="scoreLevel"></score-level>
      </el-tab-pane>
    </el-tabs>
    <div class="toolbox" v-if="activeName == 'report'">
      <el-tooltip class="item" effect="dark" content="下载pdf文件" placement="top-end">
        <div class="side-bar-button" @click="print">
          <i class="el-icon-download" style="color: #1c84c6; font-size: 30px"></i>
          <p style="font-size: 14px; margin: unset">pdf</p>
        </div>
      </el-tooltip>
      <el-tooltip class="item" effect="dark" content="下载所有pdf文件" placement="top-end">
        <div class="side-bar-button">
          <i class="el-icon-download" style="color: #1c84c6; font-size: 30px" @click="printAll"></i>
          <p style="font-size: 14px; margin: unset">pdf all</p>
        </div>
      </el-tooltip>
      <!--            <el-tooltip class="item" effect="dark" content="下载doc文件" placement="top-end">
                                              <div class="side-bar-button">
                                                  <i class="el-icon-download" style="color: #1c84c6; font-size: 30px"
                                                     @click="printDoc"></i>
                                                  <p style="font-size: 14px; margin: unset">doc</p>
                                              </div>
                                          </el-tooltip>-->
    </div>
  </div>
</template>

<script>
import chart from './chart'
import analysis from './analysis'
import Report from './report/Report.vue'
import ScoreLevel from '@/views/form/statistics/score/ScoreLevel.vue'
import { GET_EVALUATED_LIST, SET_TEMP_ZIP } from '@/store/mutation-types'
import JSZip from 'jszip'
import Report360 from '@/views/form/statistics/report/Report360.vue'

export default {
  name: 'ProjectStatistics',
  components: {
    chart,
    analysis,
    Report,
    ScoreLevel,
    Report360
  },
  data() {
    return {
      activeName: 'chart',
      formKey: '',
      type: ''
    }
  },
  computed: {
    columnName() {
      if (this.type == 5) {
        return '被评价部门'
      } else if (this.type == 6) {
        return '被评价人'
      } else {
        return '名称'
      }
    }
  },
  mounted() {
    this.activeName = this.$route.query.activeTab || 'chart'
  },
  created() {
    this.type = this.$route.query.type
    this.formKey = this.$route.query.key
    /*this.$router.push({
                            path: '/project/form/report',
                            query: {
                                key: this.formKey,
                                type: this.type,
                                activeTab: 'report',
                                isAll: this.columnName + '测评报告',
                                // downloadAll:true,
                            }
                        })*/
  },
  methods: {
    print() {
      this.$refs.report.downloadPDF()
    },
    printDoc() {
      this.$refs.report.exportDoc()
    },
    printAll() {
      this.$confirm('此操作耗时较长，是否打印所有报告?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          let zip = new JSZip()
          this.$store.commit(SET_TEMP_ZIP, zip)
          this.goNext(0)
        })
        .catch(() => {})
    },
    goNext(index) {
      let evaluatedList = this.$store.getters[GET_EVALUATED_LIST]
      this.$router.replace({
        path: '/project/form/statistics',
        query: {
          key: this.formKey,
          type: this.type,
          evaluated: evaluatedList[index].evaluated,
          activeTab: 'report',
          isAll: this.columnName + '测评报告',
          downloadAll: true,
          index: index
        }
      })
      // console.log(route)
      // window.open(route.href,'_blank')

      /*  console.log(route)
                                    let eleIF = document.createElement('iframe')
                                    eleIF.src = route.href
                                    eleIF.style.display = 'none'
                                    document.body.appendChild(eleIF)
                                    //防止下载2次
                                    setTimeout(function () {
                                        document.body.removeChild(eleIF)
                                    }, 3000)*/
    }
  }
}
</script>

<style scoped>
.statistics-tabs {
  padding: 20px;
}

::v-deep .el-tabs__content {
  padding: 0;
}

.toolbox {
  position: fixed;
  bottom: 30%;
  right: 5%;
}

.side-bar-button {
  box-shadow: 0 1px 4px 0 #d9d9d9;
  padding: 6px;
  color: #8c8c8c !important;
  text-align: center;
  cursor: pointer;
}

.side-bar-button:hover {
  background-color: whitesmoke;
}
</style>
